package dataInit

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"newRetailByGolang/model"
	"newRetailByGolang/variable"
	"time"
)

type MysqlInit struct {
}

var (
	err error
)

func init() {
	dsn := "root:new_password@tcp(127.0.0.1:3306)/new_retail_by_golang?charset=utf8mb4&parseTime=True&loc=Local"
	variable.Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("db error")
	}

	sqlDb, pErr := variable.Db.DB()
	if pErr != nil {
		panic("db error")
	}
	sqlDb.SetMaxIdleConns(10)
	sqlDb.SetMaxOpenConns(100)
	sqlDb.SetConnMaxLifetime(time.Hour)

	variable.Db.AutoMigrate(&model.ParticipationRecord{}, &model.RegistrationActivitie{}, &model.User{}, &model.UpgradeRecord{}, &model.Agent{}, &model.Store{}, &model.TaskRecord{}, &model.Order{}, &model.OrderGood{})
}
